{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('admin/used_classify2/index')}">分类管理</a></li>
            <li class=""><a href="{:url('admin/used_classify2/add')}">添加分类</a></li>
            <li class="layui-this">编辑分类</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form form-container" action="{:url('admin/used_classify2/update')}" method="post">
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属栏目</label>
                        <div class="layui-input-inline" style="width:160px;">
                            <select name="pid[]" class="site">
                                <option value="0">车型</option>
                                {foreach name="used_list" item="vo"}
                                {if $vo.pid == 0 and $vo.cid == 1}
                                {foreach name='used_list' item='lo'}
                                {if $lo.pid[0] == $vo.id}
                                <option value="{$lo.id}" {if $usedclassify.pid[0] == $lo.id}selected="selected"{/if}>{$lo.name}</option>
                                {/if}
                                {/foreach}
                                {/if}
                                {/foreach}
                            </select>
                        </div>
                        <div class="layui-input-inline" style="width:160px;">
                            <select name="pid[]" class="site">
                                <option value="0">品牌</option>
                                {if is_array($usedclassify.pid)}
                                {foreach name="used_list" item="vo"}
                                {if $vo.id == $usedclassify.pid[1]}
                                <option value="{$vo.id}" selected="selected">{$vo.name}</option>
                                {/if}
                                {/foreach}
                                {if $usedclassify.pid['0'] != 0 and $usedclassify.pid['1'] == 0}
                                <option value="{$usedclassify.id}" selected="selected">{$usedclassify.name}</option>
                                {/if}
                                {/if}
                            </select>
                        </div>
                        <div class="layui-input-inline" style="width:160px;">
                            <select name="pid[]">
                                <option value="0">车系</option>
                                {if is_array($usedclassify.pid)}
                                {foreach name="used_list" item="vo"}
                                {if $vo.id == $usedclassify.pid[2]}
                                <option value="{$vo.id}" selected="selected">{$vo.name}</option>
                                {/if}
                                {/foreach}
                                {if $usedclassify.pid['1'] != 0 and $usedclassify.pid['2'] == 0}
                                <option value="{$usedclassify.id}" selected="selected">{$usedclassify.name}</option>
                                {/if}
                                {/if}
                            </select>
                        </div>
                        <div class="layui-input-inline" style="width:160px;">
                            <select name="">
                                <option value="">型号</option>
                                {if is_array($usedclassify.pid)}
                                {if $usedclassify.pid['2'] != 0}
                                <option value="{$usedclassify.id}" selected="selected">{$usedclassify.name}</option>
                                {/if}
                                {/if}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">分类名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" value="{$usedclassify.name}" required  lay-verify="required" placeholder="请输入分类名称" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">别名</label>
                        <div class="layui-input-block">
                            <input type="text" name="alias" value="{$usedclassify.alias}" placeholder="（选填）请输入分类别名" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">缩略图</label>
                        <div class="layui-input-block">
                            <input type="text" name="thumb" value="{$usedclassify.thumb}" class="layui-input layui-input-inline" id="thumb">
                            <input type="file" name="file" class="layui-upload-file" id="thumb1">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">内容</label>
                        <div class="layui-input-block">
                            <textarea name="content" class="layui-textarea" id="content">{$usedclassify.content}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-input-block">
                            <input type="text" name="sort" value="{$usedclassify.sort}" required  lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input type="hidden" name="cid" value="0">
                            <input type="hidden" name="id" value="{$usedclassify.id}">
                            <input type="hidden" name="cid" value='0'>
                            <button class="layui-btn" lay-submit lay-filter="*">更新</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
                <div class="smallImg {notempty name='$usedclassify.thumb'}smallImgCss{/notempty}" style="background-image:url('{notempty name='$usedclassify.thumb'}{$usedclassify.thumb}{/notempty}');" id="thum"></div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script src="__JS__/kindeditor/kindeditor.config.js"></script>
<script src="__JS__/kindeditor/kindeditor-all-min.js"></script>
{/block}
{block name="script"}
<script>
    KindEditor.ready(function(K) {
        K.create('#content', KindEditorOptions);
    });
$(document).ready(function () {

    form.on('select',function(){
        $("select.site").next().find('dl').on('click','dd',function(){
            var jilu = '.layui-input-inline';
            var parent_id = $(this).attr('lay-value');
            var index = $(this).parents(jilu).index();

            if(parent_id != 0){
                $.ajax({
                    url:'/admin/used_classify2/jilm',
                    data:"id="+parent_id,
                    success:function(ell){
                        var i = 0;
                        xuan();

                        for(;i<ell.data.length;i++){
                            $(jilu).eq(index).find('select').append('<option value='+ell.data[i].id+'>'+ell.data[i].name+'</option>');
                            $(jilu).eq(index).find('dl').append('<dd lay-value='+ell.data[i].name+'>'+ell.data[i].name+'</dd>');
                        }
                        form.render('select');

                    }
                });
            }else{
                xuan();
                form.render('select');
            }

            function xuan(){
                // console.log(index);
                if(index != -1){
                    for(var j=0;j<4;j++){
                        if(j > (index-1)){
                            // console.log('j:'+j);
                            $(jilu).eq(j).find('select').html('');
                            $(jilu).eq(j).find('dl').html('');
                            switch(j){
                                case 0:
                                    $(jilu).eq(j).find('select').append('<option value="0">车型</option>');
                                    $(jilu).eq(j).find('dl').append('<dd lay-value="0">车型</dd>');
                                    continue;
                                case 1:
                                    $(jilu).eq(j).find('select').append('<option value="0">品牌</option>');
                                    $(jilu).eq(j).find('dl').append('<dd lay-value="0">品牌</dd>');
                                    continue;
                                case 2:
                                    $(jilu).eq(j).find('select').append('<option value="0">车系</option>');
                                    $(jilu).eq(j).find('dl').append('<dd lay-value="0">车系</dd>');
                                    continue;
                                case 3:
                                    $(jilu).eq(j).find('select').append('<option value="">型号</option>');
                                    $(jilu).eq(j).find('dl').append('<dd lay-value="">型号</dd>');
                                    continue;
                            }
                        }
                    }
                }
            }

        });
    });



});
</script>
{/block}